#include "../include/event_struct.h"
#include "../include/util.h"
#include <stdlib.h>
#ifndef __MIN_HEAP_H
#define __MIN_HEAP_H
// 比较两个键值的大小
#define __key_cmp(a, b) ((a)->key > (b)->key)
// 获取父亲节点
#define __get_parent(idx) (((idx)-1) / 2)
// 获取左孩子节点
#define __get_child_left(idx) (2 * ((idx) + 1))

typedef struct min_heap
{
    struct event **p; // event*数组
    unsigned n;       // 队列元素的多少
    unsigned a;       // 队列空间的大小
} min_heap_t;

int min_heap_reserve(min_heap_t *s, unsigned int n);
int min_heap_push(min_heap_t *s, struct event *e);
int min_heap_pop(min_heap_t *s, struct event *e);
void min_heap_shift_up_(min_heap_t *s, unsigned hole_index, struct event *e);
void min_heap_shift_down_(min_heap_t *s, unsigned int hole_index, struct event *e);
int min_heap_elem_greater(struct event *a, struct event *b);
int min_heap_elt_is_top(const struct event *e);
int min_heap_size(min_heap_t *s);
int miheadern_heap_erase(min_heap_t* s, struct event* e);
int min_heap_erase(min_heap_t* s, struct event* e);
#endif